package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportExpense;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2021-02-24 15:59:36
 */
@Repository
public class TransportExpenseDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportExpenseDao.class);

    public TransportExpense insert(final TransportExpense transportExpense) {
        insert("TransportExpense.insert", transportExpense);
        return transportExpense;
    }

    public Boolean updateInfoById(final TransportExpense transportExpense) {
        return update("TransportExpense.updateInfoById", transportExpense) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportExpense.updateInfoByQuery", query) > 0;
    }

    public TransportExpense selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportExpense.selectById", query);
    }

    public List<TransportExpense> selectByQuery(final Query query) {
        return queryForList("TransportExpense.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportExpense.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportExpense transportExpense = new TransportExpense();
        transportExpense.setDeleteFlag(1);
        transportExpense.setId(id);
        transportExpense.setEntId(entId);

        return update("TransportExpense.updateInfoById", transportExpense) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportExpense.deleteById", query) > 0;
    }

    //Join关联查询
    public List<TransportExpense> selectJoinSecondaryForPage(final Query query) {
        return queryForList("TransportExpense.selectJoinSecondaryByQuery", query);
    }

    public Long countJoinSecondaryByQuery(final Query query) {
        return queryForObject("TransportExpense.countJoinSecondaryByQuery", query);
    }

    //统计-报销
    public List<Map<String, String>> statisticExpense(final Query query) {
        return queryForList("TransportExpense.statisticExpense", query);
    }

    //统计-报销（各渠道）
    public List<Map<String, String>> statisticExpenseByType(final Query query) {
        return queryForList("TransportExpense.statisticExpenseByType", query);
    }

    //统计-综合报销（各项目）
    public List<Map<String, String>> statisticZHExpense(final Query query) {
        return queryForList("TransportExpense.statisticZHExpense", query);
    }
}